/**
*
* @author
*
*/
class Enemy extends egret.DisplayObjectContainer {

    private _enemyArm: dragonBones.FastArmature;
    private _enemyDisplay: egret.DisplayObjectContainer;
    private _timeList: Object;

    private static _timeTable: Object = {
        'kulou': { 'appearTime': 2150,'shoujiTime': 950 },
        'shachong': { 'appearTime': 4000,'shoujiTime': 380 },
        'shuyao': { 'appearTime': 2350,'shoujiTime': 750 },
        'yezhu': { 'appearTime': 3450,'shoujiTime': 300 },
        'long': {'appearTime': 3450,'shoujiTime': 300 }
    };

    private static _skewTable: Object = {
        'kulou': true,
        'shachong': true,
        'shuyao': false,
        'yezhu': true
    };

    public constructor(name: string,posX: number,posY: number) {
        super();

        this._timeList = Enemy._timeTable[name];

        if(Enemy._skewTable[name]) {
            this.skewY = 180;
        }

        this.x = posX;
        this.y = posY;
        this.alpha = 0;

        this._enemyArm = AniFactory.produce(
            'enemyani/' + name + '/ani.json',
            'enemyani/' + name + '/texture.json',
            'enemyani/' + name + '/texture.png',
            'enemy' + name);

        this._enemyDisplay = this._enemyArm.display;

        this.hide();

        this.addChild(this._enemyDisplay);
    }

    public show(): void {
        egret.Tween.get(this).set({ alpha: 1 }).call(function() {
            this._enemyArm.animation.gotoAndPlay('appear');
        }).wait(this._timeList['appearTime']).call(function() {
            this._enemyArm.animation.gotoAndPlay('idle');
        });
    }

    public hide(): void {
        this.alpha = 0;
        this._enemyArm.animation.gotoAndStop('appear',0);
    }

    public hurt(): void {
        egret.Tween.get(this).call(function() {
            this._enemyArm.animation.gotoAndPlay('shouji3');
        }).wait(this._timeList['shoujiTime']).call(function() {
            this._enemyArm.animation.gotoAndPlay('idle');
        });
    }

    public die(): void {
        egret.Tween.get(this).call(function() {
            this._enemyArm.animation.gotoAndPlay('die');
        }).to({
            alpha: 0
        },2000);
    }
}
